package os;

import vm.*;
import memory.*;

/**
 *
 * @author Paulius Dambrauskas
 */
public class VirtualMachine extends Process{
    //public  Processor proc;
    private int VMnumber;
    @Override
    public void create(){
        
        this.regs.put("MODE", VM.mode+"");
        this.regs.put("PTR", VM.pageTableStart/16+"");
        this.regs.put("PI", "0");
        this.regs.put("TI", "10");
        this.regs.put("SI", "0");
        this.regs.put("PC", "0");
        this.regs.put("R", "0");
        this.regs.put("C", "0");
        this.regs.put("SP", "0");
        
    }
    @Override
    public void runProcess() {
        VM.mode = 0;
        VMnumber = Integer.parseInt(extra)-1; 
       
        
        
        OS.window.processor.getPTR().setRegisterValue(VM.pageTableStart/16+VMnumber+"");
        int i = 0;
        while(!Memory.getMemory().get(VMnumber*16+i).wordValue.getValue().equals("") && !Memory.getMemory().get(VMnumber*16+i).wordValue.getValue().equals(" ") && i < 16){
            System.out.println(i+Memory.getMemory().get(VMnumber*16+i).wordValue.getValue());
          i++;  
        }
        OS.window.processor.getSP().setRegisterValue(239+i+"");
        OS.window.processor.intiRegisters(this);
        OS.window.initVirtualMemory();
        OS.window.processor.endInterrupt();

        
    }
    
    @Override
    public void step(){
        OS.window.processor.step();
        this.setStepValue(Integer.parseInt(this.regs.get("PC")));
    }
    
}
